<?php

// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://demo.thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库：https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------

namespace app\index\controller;

use function PHPSTORM_META\type;
use think\admin\Controller;


/**
 * Class Index
 * @package app\index\controller
 */
class Login extends BaseController
{

    public $table = "CmsUser";

    public function index()
    {
        $this->title = '用户登录';
        $this->fetch();
    }

    public function dialog()
    {
        $this->title = '用户登录对话框';
        $this->fetch();
    }

    /**
     * 登录逻辑验证
     */
    public function check()
    {
        $data = $this->request->post();
        $map = ["username"=>$data['username']];

        $user = $this->app->db->name($this->table)->where($map)->find();
        if(!$user){
            $map = ["contact_phone"=>$data['username']];
            $user = $this->app->db->name($this->table)->where($map)->find();
        }

        if(!$user){
            $this->error("用户名和密码不匹配");
        }

        if($user['password']!=$data['password']){
            $this->error("用户名和密码不匹配");
        }

        $this->app->session->set('member', $user);
        $this->success("登录成功");
    }

    public function doOut(){
        $this->app->session->set('member', null);
    }


}